package cn.tedu.luban.demand.main.controller;

import cn.tedu.luban.demand.main.converter.DemandConverter;
import cn.tedu.luban.demand.main.service.RequestOrderService;
import cn.tedu.luban.demand.protocol.VO.RequestOrderListItemVO;
import cn.tedu.luban.demand.protocol.bo.RequestOrderBO;
import cn.tedu.luban.demand.protocol.query.RequestOrderQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import com.tedu.inn.protocol.pager.PagerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemandController {
    /**
     * 手机端师傅查询符合要求条件的需求单分页数据
     * 按照创建时间从上到下,或者按照筛选条件 距离筛选 价格筛选 时间筛选 种类筛选
     */
    @Autowired
    private RequestOrderService requestOrderService;
    @Autowired
    private DemandConverter  demandConverter;
    @PostMapping("/demand/order/search")
    public Result<PagerResult<RequestOrderListItemVO>>
        searchRequestOrders(@RequestBody RequestOrderQuery query)throws BusinessException{
        //1. 分页数据业务层返回值 page要求5个属性 pageNo pageSize list total lastIndexPage
        ListRecordTotalBO<RequestOrderBO> bos=requestOrderService.searchRequestOrders(query);
        //2. 转换器转换
        PagerResult<RequestOrderListItemVO> pagerResult = demandConverter.assemblePagerResult(bos, query);
        return new Result<>(pagerResult);
    }
}
